package net.soevar.database.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(schema = "public", name = "ath_role")
public class AthRole implements Serializable {

	private static final long serialVersionUID = 256957505504106823L;
	private static final String ADMINISTRATOR = "am";

	private String roleId;
	private String roleName;
	private Set<AthMenu> menus = new HashSet<AthMenu>();
	private String dirubahOleh;
	private Date dirubahTanggal = new Date();

	public AthRole() {
	}

	public AthRole(String roleId) {
		this.roleId = roleId;

	}

	public AthRole(String roleId, String roleName) {
		this.roleId = roleId;
		this.roleName = roleName;
	}

	@Id
	@Column(name = "roleid", unique = true, nullable = false, length = 10)
	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	@Column(name = "rolename", nullable = true, length = 100)
	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	@ManyToMany(targetEntity = AthMenu.class, cascade = { CascadeType.MERGE,
			CascadeType.REMOVE, CascadeType.PERSIST })
	@OrderBy(value = "root asc, child asc")
	@JoinTable(name = "ath_role_has_menu", joinColumns = @JoinColumn(name = "ath_role"), inverseJoinColumns = @JoinColumn(name = "ath_menu"))
	public Set<AthMenu> getMenus() {
		return menus;
	}

	public void setMenus(Set<AthMenu> menus) {
		this.menus = menus;
	}

	@Column(name = "dirubah_oleh", length = 100)
	public String getDirubahOleh() {
		return dirubahOleh;
	}

	public void setDirubahOleh(String dirubahOleh) {
		this.dirubahOleh = dirubahOleh;
	}

	@Column(name = "dirubah_tanggal")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getDirubahTanggal() {
		return dirubahTanggal;
	}

	public void setDirubahTanggal(Date dirubahTanggal) {
		this.dirubahTanggal = dirubahTanggal;
	}

}
